package com.bana.fvs.app.module.tab2;

import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.bana.fvs.R;
import com.bana.fvs.app.base.BaseFragment;
import com.bana.fvs.app.base.PageBaseParams;
import com.bana.fvs.app.common.ConstantsField;
import com.bana.fvs.app.common.adapter.CommonAdapter;
import com.bana.fvs.app.common.adapter.ViewHolder;
import com.bana.fvs.app.main.entity.FogZoneListItemBean;
import com.bana.fvs.app.module.detaile.EquipmentDetailActivity;
import com.bana.fvs.app.module.tab2.entity.ControlResultBean;
import com.bana.fvs.app.module.tab2.entity.PushVisibilityBean;
import com.bana.fvs.app.module.tab2.tab2Detail.adapter.Tab2CommonInnerAdapter;
import com.bana.fvs.app.module.tab2.tab2Detail.entity.EquipListItemBean;
import com.bana.fvs.app.module.tab2.tab2Detail.entity.PopWindowItemBean;
import com.bana.fvs.app.mvp.ConstantsValue;
import com.bana.fvs.app.mvp.contract.EquipListContract;
import com.bana.fvs.app.mvp.presenter.EquipListPresenter;
import com.bana.fvs.app.other.xrecyclerview.ProgressStyle;
import com.bana.fvs.app.other.xrecyclerview.XRecyclerView;
import com.bana.fvs.app.util.TimeUtils;
import com.bana.fvs.app.util.UserInfoUtils;
import com.bana.fvs.app.view.SpinerPopWindow;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.wei.commonlibrary.manager.RxBus;
import com.wei.commonlibrary.net.CommException;
import com.wei.commonlibrary.utils.DisplayUtil;
import com.wei.commonlibrary.utils.GlobalContext;
import com.wei.commonlibrary.utils.SPUtils;
import com.wei.commonlibrary.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import rx.Observable;
import rx.functions.Action1;

/**
 * Author : yanftch
 * Date : 2018/2/26
 * Time : 16:41
 * Desc : 第二个TAB，外层通用Fragment
 */

/**
 * 外部传递index索引值
 * 0-能见度检测仪
 * 1-区域控制器
 * 2-雾灯
 */
public class VisibilityFragment extends BaseFragment<EquipListPresenter> implements EquipListContract.IEquipListView {
    private static final String TAG = "dah_VisibilityFragment";
    @BindView(R.id.recyclerView)
    XRecyclerView mXRecyclerView;
    @BindView(R.id.buttonLeft)
    TextView mTvButtonLeft;
    @BindView(R.id.buttonRight)
    TextView mTvButtonRight;
    @BindView(R.id.tv_middle_line)
    TextView mTvmiddleLine;

    private Tab2CommonInnerAdapter mAdapter;
    private List<EquipListItemBean> datas;

    private SpinerPopWindow leftSpinner;
    private SpinerPopWindow rightSpinner;
    private List<FogZoneListItemBean> rightDatas;
    private List<FogZoneListItemBean> leftDatas;


    public class Params extends PageBaseParams {
        public static final String index_p = "_index_";
        public static final String index_type = "_index_type_";


        public static final String request_param_sblx_01 = "01";
        public static final String request_param_sblx_02 = "02";
        public static final String request_param_sblx_03 = "03";
        public static final String request_param_sblx_04 = "04";


        public static final String getRequest_param_sbzt_1 = "1";
        public static final String request_param_sbzt_2 = "2";
        public static final String request_param_sbzt_9 = "9";
    }

    /**
     * index=0---能见度检测仪
     * index=1---雾灯
     * index=2---区域控制器
     * index=4---气象仪
     */
    private int index;
    /**
     * 接口请求参数
     */
    private String request_param_sblx = "01";//设备类型    01-能见度检测仪    02-区域控制器   03-雾灯  04-气象仪
    private String request_param_sbzt = "9";//设备状态    0-正常   1-故障    9-全部
    private int request_param_pagenum = 1;//页码
    private String request_param_wqbm = "";//雾区编码

    private boolean hasFetchData; // 标识已经触发过懒加载数据
    private boolean isViewPrepared; // 标识fragment视图已经初始化完毕


    public static VisibilityFragment newInstance(int type) {
        Bundle args = new Bundle();
        args.putInt(Params.index_type, 0);
        VisibilityFragment fragment = new VisibilityFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected int setLayout() {
        return R.layout.layout_fragment_common;
    }

    @Override
    protected void initView(View rootView) {
        mTvButtonLeft.setSelected(false);
        mTvButtonRight.setSelected(false);
        int width = DisplayUtil.dp2px(mContext, 120);
        mTvButtonLeft.setWidth(width);
        mTvButtonRight.setWidth(width);

        index = getArguments().getInt(Params.index_type);
        rightDatas = new ArrayList<>();
        String[] stringArray = getResources().getStringArray(R.array.equipment_state);
        if (stringArray != null && stringArray.length != 0) {
            FogZoneListItemBean bean3 = new FogZoneListItemBean();
            bean3.setWqmc(stringArray[0]);
            bean3.setWqbm(ConstantsValue.CONTROL_STATUS_2);
            rightDatas.add(bean3);
            FogZoneListItemBean bean4 = new FogZoneListItemBean();
            bean4.setWqmc(stringArray[1]);
            bean4.setWqbm(ConstantsValue.CONTROL_STATUS_1);
            rightDatas.add(bean4);
            FogZoneListItemBean bean5 = new FogZoneListItemBean();
            bean5.setWqmc(stringArray[2]);
            bean5.setWqbm(ConstantsValue.CONTROL_STATUS_9);
            rightDatas.add(bean5);
        }
        rightSpinner = new SpinerPopWindow(mContext, rightDatas);
        Gson gson = new Gson();
        String stringData = SPUtils.getStringData(mContext, ConstantsValue.JSON_DATA);
        if (!TextUtils.isEmpty(stringData)) {
            List<FogZoneListItemBean> retList = gson.fromJson(stringData, new TypeToken<List<FogZoneListItemBean>>() {
            }.getType());
            leftDatas = new ArrayList<>();
            leftDatas.addAll(retList);
//            FogZoneListItemBean bean = new FogZoneListItemBean();
//            bean.setWqmc("全部");
//            bean.setWqbm("");//全部，传""
//            leftDatas.add(bean);
            leftSpinner = new SpinerPopWindow(mContext, leftDatas);
            if(leftDatas.size()>0) {
                leftSpinner.dismiss();
                request_param_wqbm = leftDatas.get(0).getWqbm();
                mTvButtonLeft.setText(leftDatas.get(0).getWqmc());
            }
        }
        setListener();
    }

    private void setListener() {
        leftSpinner.setOnItemClickListener(new SpinerPopWindow.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                leftSpinner.dismiss();
                request_param_wqbm = leftDatas.get(position).getWqbm();
                mTvButtonLeft.setText(leftDatas.get(position).getWqmc());
                http_getData();
                boolean selected = mTvButtonLeft.isSelected();
                Log.e(TAG, "onItemClick: selected===" + selected);
            }

            @Override
            public void onDismiss() {
                boolean selected = mTvButtonLeft.isSelected();
                Log.e(TAG, "onDismiss:   selected=== " + selected);
                mTvButtonLeft.setSelected(!selected);
                handleLeft(selected);
            }
        });
        rightSpinner.setOnItemClickListener(new SpinerPopWindow.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                rightSpinner.dismiss();
                request_param_sbzt = rightDatas.get(position).getWqbm();
                mTvButtonRight.setText(rightDatas.get(position).getWqmc());
                //http_getData();
                mAdapter.setSbzt(request_param_sbzt);
                boolean selected = mTvButtonRight.isSelected();
                Log.e(TAG, "onItemClick: selected===" + selected);
            }

            @Override
            public void onDismiss() {
                boolean selected = mTvButtonRight.isSelected();
                Log.e(TAG, "onDismiss:   selected=== " + selected);
                mTvButtonRight.setSelected(!selected);
                handleRight(selected);
            }
        });
    }

    @Override
    protected void widgetClick(View v) {
        switch (v.getId()) {
            case R.id.buttonLeft:
                if (leftSpinner == null) {
                    ToastUtil.showShort(getActivity().getApplicationContext(), getString(R.string.get_fogArea_list_error));
                    return;
                }
                boolean isSelected = mTvButtonLeft.isSelected();
                //默认是FALSE的对吧
                //
                Log.e(TAG, "widgetClick: isSelected===" + isSelected);
                handleLeft(isSelected);
                updateStatus(!isSelected, false);
                if (!isSelected && leftSpinner != null) {
                    leftSpinner.setWidth(mTvButtonLeft.getWidth());
                    leftSpinner.showAsDropDown(mTvButtonLeft);
                }
                break;
            case R.id.buttonRight:
                boolean isSelectedRight = mTvButtonRight.isSelected();
                Log.e(TAG, "widgetClick: isSelectedRight===" + isSelectedRight);
                handleRight(isSelectedRight);
                updateStatus(false, !isSelectedRight);
                if (!isSelectedRight && rightSpinner != null) {
                    rightSpinner.setWidth(mTvButtonRight.getWidth());
                    rightSpinner.showAsDropDown(mTvButtonRight);
                }
                break;
            default:
                break;
        }
    }

    @Override
    protected void initWidget() {
        mXRecyclerView.setRefreshProgressStyle(ProgressStyle.LineScalePulseOutRapid);
        if (index == 0) {
            request_param_sblx = Params.request_param_sblx_01;
        } else if (index == 1) {
            request_param_sblx = Params.request_param_sblx_04;
        } else if (index == 2) {
            request_param_sblx = Params.request_param_sblx_02;
        }
        mTvButtonLeft.setOnClickListener(this);
        mTvButtonRight.setOnClickListener(this);

        datas = new ArrayList<>();
        mAdapter = new Tab2CommonInnerAdapter(datas, index);

        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mXRecyclerView.setLayoutManager(layoutManager);
        mXRecyclerView.setPullRefreshEnabled(true);//下拉刷新-可以
        mXRecyclerView.setLoadingMoreEnabled(true);//上拉加载-可以
        mXRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);//设置下拉刷新的样式
        mXRecyclerView.setAdapter(mAdapter);
        mXRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                request_param_pagenum = 1;
                http_getData();
            }

            @Override
            public void onLoadMore() {
                // TODO: 2018/3/12 传新的页码！！！！！！！！！
                http_getData();
            }
        });
        mAdapter.setOnItemClickListener(position -> {
            if (index == 0) {
                //EquipmentDetailActivity.startAction(mContext, ConstantsField.INDEX_0, datas.get(position).getJcybm(), null);
                EquipmentDetailActivity.startAction(mContext, ConstantsField.INDEX_0, datas.get(position));
            } else if (index == 1) {
                EquipmentDetailActivity.startAction(mContext, ConstantsField.INDEX_4, Integer.toString(datas.get(position).getKey()), null);
            } else if (index == 2) {
                EquipmentDetailActivity.startAction(mContext, ConstantsField.INDEX_1, datas.get(position).getKzqbm(), null);
            }
        });
        /**
         * 右边的HandleICON点击事件
         */
        mAdapter.setOnHandleBtnClickListener((position, view) -> showPopupwindow(datas.get(position), view));
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        isViewPrepared = true;
        requestData();

        RxBus.getInstance().onEvent(RxBus.getInstance().register("update_visibility"), new Action1<Object>() {
            @Override
            public void call(Object obj) {
                if (obj == null) return;
                String jsonStr = (String) obj;
                PushVisibilityBean pushVisibilityBean = new Gson().<PushVisibilityBean>fromJson(jsonStr, new TypeToken<PushVisibilityBean>() {
                }.getType());
                checkItem(pushVisibilityBean);
            }
        });
    }

    private void checkItem(PushVisibilityBean pushVisibilityBean) {
        if (datas == null || datas.size() == 0) return;

        int size = datas.size();
        String pushBm = String.valueOf(pushVisibilityBean.getJcybsm());
        for (int i = 0; i < size; i++) {
            EquipListItemBean equipListItemBean = datas.get(i);
            if (TextUtils.equals(equipListItemBean.getJcybm(), pushBm)) {
                equipListItemBean.setSbzt(String.valueOf(pushVisibilityBean.getJcysbzt()));
                break;
            }
        }
        mAdapter.notifyDataSetChanged();
    }


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        Log.e(TAG, "311 ,setUserVisibleHint: isVisibleToUser = " + isVisibleToUser);
        if (isVisibleToUser) {
            requestData();
        } else {
            postMessage();
        }
    }

    private void postMessage() {
        String updateTime = TimeUtils.getCurrentTime();
        if (datas != null && datas.size() > 0) {
            updateTime = datas.get(datas.size() - 1).getGxsjgs();
            if (TextUtils.isEmpty(updateTime)) {
                updateTime = TimeUtils.getCurrentTime();
            }
        }
        RxBus.getInstance().post("update_time", updateTime);
    }

    private void requestData() {
        if (getUserVisibleHint() && !hasFetchData && isViewPrepared) {
            hasFetchData = true;
            http_getData();
        }
    }

    private void showPopupwindow(EquipListItemBean equipListItemBean, View anchorView) {
        final PopupWindow popupWindow = new PopupWindow(mContext);
        popupWindow.setFocusable(true);
        int width = 0, height = 0;
        width = DisplayUtil.dp2px(mContext, 102);
        if (index == 1) {
            height = DisplayUtil.dp2px(mContext, 220);
            width = DisplayUtil.dp2px(mContext, 110);
        } else {
            height = DisplayUtil.dp2px(mContext, 113);
        }
        popupWindow.setWidth(width);
        popupWindow.setHeight(height);
        //popupWindow.setAnimationStyle(R.style.anim_menu_bottombar);//设置动画效果
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        View view = View.inflate(mContext, R.layout.layout_pop_view, null);
        ListView listView = view.findViewById(R.id.popListView);
        List<PopWindowItemBean> datas = new ArrayList<>();

        /**
         *----------------------------------------------------------------------------------------------------
         */
        if (index == 1) {
            PopWindowItemBean bean = new PopWindowItemBean();
            bean.setPopName(getResources().getString(R.string.mandatory_yellow_light));
            bean.setPopCode(ConstantsValue.CONTROL_STATUS_YELLO);
            bean.setPopLeftDrawable(R.drawable.pop_yellow);
            datas.add(bean);
            PopWindowItemBean bean1 = new PopWindowItemBean();
            bean1.setPopName(getResources().getString(R.string.mandatory_red_light));
            bean1.setPopCode(ConstantsValue.CONTROL_STATUS_RED);
            bean1.setPopLeftDrawable(R.drawable.pop_red);
            datas.add(bean1);
            PopWindowItemBean bean2 = new PopWindowItemBean();
            bean2.setPopName(getResources().getString(R.string.check_red_light));
            bean2.setPopCode(ConstantsValue.CONTROL_STATUS_VEHRED);
            bean2.setPopLeftDrawable(R.drawable.pop_car_charge);
            datas.add(bean2);
            PopWindowItemBean bean3 = new PopWindowItemBean();
            bean3.setPopName(getResources().getString(R.string.foglight_close));
            bean3.setPopCode(ConstantsValue.CONTROL_STATUS_CLOSE);
            bean3.setPopLeftDrawable(R.drawable.pop_close);
            datas.add(bean3);
            PopWindowItemBean bean4 = new PopWindowItemBean();
            bean4.setPopName(getResources().getString(R.string.foglight_start));
            bean4.setPopCode(ConstantsValue.CONTROL_STATUS_OPEN);
            bean4.setPopLeftDrawable(R.drawable.pop_open);
            datas.add(bean4);
            PopWindowItemBean bean5 = new PopWindowItemBean();
            bean5.setPopName(getResources().getString(R.string.foglight_restart));
            bean5.setPopCode(ConstantsValue.CONTROL_STATUS_RESTART);
            bean5.setPopLeftDrawable(R.drawable.pop_restart);
            datas.add(bean5);
        } else if (index == 0 || index == 2) {
            PopWindowItemBean bean3 = new PopWindowItemBean();
            bean3.setPopName(getResources().getString(R.string.foglight_close));
            bean3.setPopCode(ConstantsValue.CONTROL_STATUS_CLOSE);
            bean3.setPopLeftDrawable(R.drawable.pop_close);
            datas.add(bean3);
            PopWindowItemBean bean4 = new PopWindowItemBean();
            bean4.setPopName(getResources().getString(R.string.foglight_start));
            bean4.setPopCode(ConstantsValue.CONTROL_STATUS_OPEN);
            bean4.setPopLeftDrawable(R.drawable.pop_open);
            datas.add(bean4);
            PopWindowItemBean bean5 = new PopWindowItemBean();
            bean5.setPopName(getResources().getString(R.string.foglight_restart));
            bean5.setPopCode(ConstantsValue.CONTROL_STATUS_RESTART);
            bean5.setPopLeftDrawable(R.drawable.pop_restart);
            datas.add(bean5);
        }
        /**
         *----------------------------------------------------------------------------------------------------
         */
        CommonAdapter<PopWindowItemBean> adapter;
        adapter = new CommonAdapter<PopWindowItemBean>(datas, R.layout.item_layout_pop_lv_item) {
            @Override
            public void convert(ViewHolder holder, PopWindowItemBean item) {
                if (index == 1) {
                    LinearLayout ll_container = holder.getView(R.id.item_ll_container);
                    ll_container.setGravity(Gravity.LEFT);
                    ll_container.setPadding(DisplayUtil.dp2px(mContext, 10), ll_container.getPaddingTop(), 0, ll_container.getPaddingBottom());
                } else if (index == 0 || index == 2) {
                    LinearLayout ll_container = holder.getView(R.id.item_ll_container);
                    ll_container.setGravity(Gravity.CENTER);
                    ll_container.setPadding(0, ll_container.getPaddingTop(), 0, ll_container.getPaddingBottom());
                }
                //文字
                if (!TextUtils.isEmpty(item.getPopName()))
                    holder.setText(R.id.popTextView, item.getPopName());
                //左边ICON
                if (item.getPopLeftDrawable() != -1)
                    holder.setImageResource(R.id.popImageView, item.getPopLeftDrawable());
            }
        };

        listView.setAdapter(adapter);
        listView.setOnItemClickListener((parent, view1, position1, id) -> {
            PopWindowItemBean bean0 = datas.get(position1);
            String kzcz = bean0.getPopCode();//控制操作
            String sbbm = "";
            if (equipListItemBean != null) {
                sbbm = Integer.toString(equipListItemBean.getKey());
            }
            ToastUtil.showLong(mContext, bean0.toString());
            Log.e(TAG, "showPopupwindow: sbbm===" + sbbm + "    sbbm===" + kzcz);
            if (index == 0) {
                //能见度检测仪修改
                mFPresenter.http_controlVisibility(getActivity(), UserInfoUtils.getInstance().getToken(mContext), sbbm, kzcz);
            } else if (index == 2) {
                //区域控制器修改
//                mFPresenter.http_controlController(getActivity(), UserInfoUtils.getInstance().getToken(mContext), sbbm, kzcz);
            } else if (index == 1) {
                //雾灯修改
                mFPresenter.http_controlLamp(getActivity(), UserInfoUtils.getInstance().getToken(mContext), sbbm, kzcz);
            }
            popupWindow.dismiss();
        });
        popupWindow.setContentView(view);
        int[] locations = new int[2];
        anchorView.getLocationOnScreen(locations);//获取当前控件在屏幕上的位置
        popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, locations[0] - width + anchorView.getWidth(), locations[1] + anchorView.getHeight());
    }

    /**
     * @param leftStatus
     * @param rightStatus
     */
    private void updateStatus(boolean leftStatus, boolean rightStatus) {
        mTvButtonLeft.setSelected(leftStatus);
        mTvButtonRight.setSelected(rightStatus);
        mTvmiddleLine.setVisibility(!leftStatus && !rightStatus ? View.GONE : View.VISIBLE);
    }

    @Override
    protected void initPrsenter() {
        mFPresenter.setView(this);
    }

    @Override
    public void onError(CommException e) {
        mXRecyclerView.refreshComplete();
        if (request_param_pagenum == 1) {
            mXRecyclerView.refreshComplete();
        } else {
            mXRecyclerView.loadMoreComplete();
        }

        if (TextUtils.isEmpty(e.getMessage()) || TextUtils.equals("null", e.getMessage())) {
            ToastUtil.showShort(mContext, mContext.getString(R.string.hint_get_list_error));
        } else
            ToastUtil.showShort(GlobalContext.context, e.getMessage());
    }

    @Override
    public void onResponse(List<EquipListItemBean> equipListItemBeans) {
        mXRecyclerView.refreshComplete();
        if (null != equipListItemBeans && !equipListItemBeans.isEmpty()) {
            List<EquipListItemBean> subList=new ArrayList<>();
            for (EquipListItemBean itembena : equipListItemBeans) {
                if ("1".equals(Integer.toString(itembena.getType()))) {
                    subList.add(itembena);
                }
            }

            if (request_param_pagenum == 1) {
                //刷新数据
                datas.clear();
                datas.addAll(subList);
                mXRecyclerView.refreshComplete();
            } else {
                datas.addAll(subList);
                mXRecyclerView.loadMoreComplete();
            }
            postMessage();
            mAdapter.notifyDataSetChanged();
        } else {
            if (datas != null && datas.size() > 0) {
                datas.clear();
                mAdapter.notifyDataSetChanged();
//                ToastUtil.showShort(mContext, mContext.getString(R.string.hint_get_list_null));
            } else {
                ToastUtil.showShort(mContext, mContext.getString(R.string.hint_get_list_error));
            }
        }
    }

    public void http_getData() {
        mFPresenter.http_getEquipList(getActivity(), UserInfoUtils.getInstance().getToken(mContext), request_param_sblx, request_param_sbzt, request_param_wqbm, request_param_pagenum);
    }

    /**
     * 能见度检测仪修改结果
     */
    @Override
    public void onVisibilityResult(ControlResultBean bean) {
        if (bean.isKzzt()) {
            ToastUtil.showShort(mContext, getString(R.string.tip_toast_update_success));
        } else {
            ToastUtil.showShort(mContext, bean.getSbyy());
        }
    }

    /**
     * 区域控制器修改结果
     *
     * @param bean
     */
    @Override
    public void onControllerResult(ControlResultBean bean) {
        if (bean.isKzzt()) {
            ToastUtil.showShort(mContext, getString(R.string.tip_toast_update_success));
        } else {
            ToastUtil.showShort(mContext, getString(R.string.tip_toast_update_error));
        }
    }

    /**
     * 雾灯控制结果
     *
     * @param bean
     */
    @Override
    public void onLampResult(ControlResultBean bean) {
        if (bean.isKzzt()) {
            ToastUtil.showShort(mContext, getString(R.string.tip_toast_update_success));
        } else {
            ToastUtil.showShort(mContext, bean.getSbyy());
        }
    }

    /**
     * 处理左边事件
     *
     * @param selected
     */
    private void handleLeft(boolean selected) {
        if (!selected) {
            mTvButtonLeft.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.tab2_left_checked), null, getResources().getDrawable(R.drawable.tab2_arrow_checked), null);
        } else {
            mTvButtonLeft.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.tab2_left_unchecked), null, getResources().getDrawable(R.drawable.tab2_arrow_unchecked), null);
        }
    }

    /**
     * 处理右边事件
     *
     * @param selected
     */
    private void handleRight(boolean selected) {
        if (!selected) {
            mTvButtonRight.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.tab2_right_checked), null, getResources().getDrawable(R.drawable.tab2_arrow_checked), null);
        } else {
            mTvButtonRight.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.tab2_right_unchecked), null, getResources().getDrawable(R.drawable.tab2_arrow_unchecked), null);
        }
    }

}
